CSharpTest.Net
SaltedData Constructor(Byte[],Size)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > SaltedData Class > SaltedData Constructor : SaltedData Constructor(Byte[],Size)

saltedData
szSalt

Glossary Item Box

Seperates the salt from the data provided

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal saltedData() As Byte, _
   ByVal szSalt As Salt.Size _
)
C# 
public SaltedData( 
   byte[] saltedData,
   Salt.Size szSalt
)

Parameters

saltedData
szSalt

Example

Library/Library.Test/TestSalt.cs

C#Copy Code
Salt s = new Salt(Salt.Size.b64);
byte[] testData = new byte[8];
new Random().NextBytes(testData);
byte[] tmp;

using (SaltedData sd = new SaltedData(s, testData))
{
    Assert.AreEqual(16, sd.Length);
    Assert.AreEqual(s, sd.Salt);
    Assert.AreEqual(testData, sd.GetDataBytes());

    tmp = sd.ToArray();
    Assert.AreEqual(16, tmp.Length);
    Assert.AreEqual(tmp, IOStream.ReadAllBytes(sd.ToStream()));
}

using (SaltedData sd = new SaltedData(s, new MemoryStream(testData)))
{
    Assert.AreEqual(s, sd.Salt);
    Assert.AreEqual(testData, sd.GetDataBytes());
    Assert.AreEqual(tmp, sd.ToArray());
}

using (SaltedData sd = new SaltedData(tmp, Salt.Size.b64))
{
    Assert.AreEqual(s, sd.Salt);
    Assert.AreEqual(testData, sd.GetDataBytes());
    Assert.AreEqual(tmp, sd.ToArray());
}
VB.NETCopy Code
Dim s As New Salt(Salt.Size.b64)
Dim testData As Byte() = New Byte(8) {}
New Random().NextBytes(testData)
Dim tmp As Byte()

Using sd As New SaltedData(s, testData)
    Assert.AreEqual(16, sd.Length)
    Assert.AreEqual(s, sd.Salt)
    Assert.AreEqual(testData, sd.GetDataBytes())

    tmp = sd.ToArray()
    Assert.AreEqual(16, tmp.Length)
    Assert.AreEqual(tmp, IOStream.ReadAllBytes(sd.ToStream()))
End Using

Using sd As New SaltedData(s, New MemoryStream(testData))
    Assert.AreEqual(s, sd.Salt)
    Assert.AreEqual(testData, sd.GetDataBytes())
    Assert.AreEqual(tmp, sd.ToArray())
End Using

Using sd As New SaltedData(tmp, Salt.Size.b64)
    Assert.AreEqual(s, sd.Salt)
    Assert.AreEqual(testData, sd.GetDataBytes())
    Assert.AreEqual(tmp, sd.ToArray())
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys